home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Magazine / GraphicsCards / StormMesa / src / vbfill.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-04  |  33.9 KB  |  1,317 lines

  1. /* $Id: vbfill.c,v 3.6 1998/06/07 22:18:52 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  3.0
  6.  * Copyright (C) 1995-1998  Brian Paul
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25.  * $Log: vbfill.c,v $
  26.  * Revision 3.6  1998/06/07 22:18:52  brianp
  27.  * implemented GL_EXT_multitexture extension
  28.  *
  29.  * Revision 3.5  1998/04/18 05:00:42  brianp
  30.  * moved FLOAT_COLOR_TO_UBYTE_COLOR macro to mmath.h
  31.  *
  32.  * Revision 3.4  1998/03/27 04:26:44  brianp
  33.  * fixed G++ warnings
  34.  *
  35.  * Revision 3.3  1998/02/20 04:53:07  brianp
  36.  * implemented GL_SGIS_multitexture
  37.  *
  38.  * Revision 3.2  1998/02/08 20:17:42  brianp
  39.  * removed unneeded headers
  40.  *
  41.  * Revision 3.1  1998/02/02 03:09:34  brianp
  42.  * added GL_LIGHT_MODEL_COLOR_CONTROL (separate specular color interpolation)
  43.  *
  44.  * Revision 3.0  1998/01/31 21:06:45  brianp
  45.  * initial rev
  46.  *
  47.  */
  48.  
  49.  
  50. /*
  51.  * This file implements the functions for filling the vertex buffer:
  52.  *   glVertex, glNormal, glColor, glIndex, glEdgeFlag, glTexCoord,
  53.  */
  54.  
  55.  
  56. #ifdef PC_HEADER
  57. #include "all.h"
  58. #else
  59. #include <assert.h>
  60. #include "context.h"
  61. #include "light.h"
  62. #include "macros.h"
  63. #include "matrix.h"
  64. #include "mmath.h"
  65. #include "pb.h"
  66. #include "types.h"
  67. #include "vb.h"
  68. #include "vbfill.h"
  69. #include "vbxform.h"
  70. #include "xform.h"
  71. #endif
  72.  
  73.  
  74.  
  75. /**********************************************************************/
  76. /******                    glNormal functions                     *****/
  77. /**********************************************************************/
  78.  
  79. /*
  80.  * Caller:  context->API.Normal3f pointer.
  81.  */
  82. void gl_Normal3f( GLcontext *ctx, GLfloat nx, GLfloat ny, GLfloat nz )
  83. {
  84.    ctx->Current.Normal[0] = nx;
  85.    ctx->Current.Normal[1] = ny;
  86.    ctx->Current.Normal[2] = nz;
  87.    ctx->VB->MonoNormal = GL_FALSE;
  88. }
  89.  
  90.  
  91. /*
  92.  * Caller:  context->API.Normal3fv pointer.
  93.  */
  94. void gl_Normal3fv( GLcontext *ctx, const GLfloat *n )
  95. {
  96.    ctx->Current.Normal[0] = n[0];
  97.    ctx->Current.Normal[1] = n[1];
  98.    ctx->Current.Normal[2] = n[2];
  99.    ctx->VB->MonoNormal = GL_FALSE;
  100. }
  101.  
  102.  
  103.  
  104. /**********************************************************************/
  105. /******                    glIndex functions                      *****/
  106. /**********************************************************************/
  107.  
  108. /*
  109.  * Caller:  context->API.Indexf pointer.
  110.  */
  111. void gl_Indexf( GLcontext *ctx, GLfloat c )
  112. {
  113.    ctx->Current.Index = (GLuint) (GLint) c;
  114.    ctx->VB->MonoColor = GL_FALSE;
  115. }
  116.  
  117.  
  118. /*
  119.  * Caller:  context->API.Indexi pointer.
  120.  */
  121. void gl_Indexi( GLcontext *ctx, GLint c )
  122. {
  123.    ctx->Current.Index = (GLuint) c;
  124.    ctx->VB->MonoColor = GL_FALSE;
  125. }
  126.  
  127.  
  128.  
  129. /**********************************************************************/
  130. /******                     glColor functions                     *****/
  131. /**********************************************************************/
  132.  
  133.  
  134. /*
  135.  * Caller:  context->API.Color3f pointer.
  136.  */
  137. void gl_Color3f( GLcontext *ctx, GLfloat red, GLfloat green, GLfloat blue )
  138. {
  139.    FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Current.ByteColor[0], red);
  140.    FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Current.ByteColor[1], green);
  141.    FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Current.ByteColor[2], blue);
  142.    ctx->Current.ByteColor[3] = 255;
  143.    ASSERT( !ctx->Light.ColorMaterialEnabled );
  144.    ctx->VB->MonoColor = GL_FALSE;
  145. }
  146.  
  147.  
  148. /*
  149.  * Caller:  context->API.Color3fv pointer.
  150.  */
  151. void gl_Color3fv( GLcontext *ctx, const GLfloat *c )
  152. {
  153.    FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Current.ByteColor[0], c[0]);
  154.    FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Current.ByteColor[1], c[1]);
  155.    FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Current.ByteColor[2], c[2]);
  156.    ctx->Current.ByteColor[3] = 255;
  157.    ASSERT( !ctx->Light.ColorMaterialEnabled );
  158.    ctx->VB->MonoColor = GL_FALSE;
  159. }
  160.  
  161.  
  162.  
  163. /*
  164.  * Caller:  context->API.Color4f pointer.
  165.  */
  166. void gl_Color4f( GLcontext *ctx,
  167.          GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha )
  168. {
  169.    FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Current.ByteColor[0], red);
  170.    FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Current.ByteColor[1], green);
  171.    FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Current.ByteColor[2], blue);
  172.    FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Current.ByteColor[3], alpha);
  173.    ASSERT( !ctx->Light.ColorMaterialEnabled );
  174.    ctx->VB->MonoColor = GL_FALSE;
  175. }
  176.  
  177.  
  178. /*
  179.  * Caller:  context->API.Color4fv pointer.
  180.  */
  181. void gl_Color4fv( GLcontext *ctx, const GLfloat *c )
  182. {
  183.    FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Current.ByteColor[0], c[0]);
  184.    FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Current.ByteColor[1], c[1]);
  185.    FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Current.ByteColor[2], c[2]);
  186.    FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Current.ByteColor[3], c[3]);
  187.    ASSERT( !ctx->Light.ColorMaterialEnabled );
  188.    ctx->VB->MonoColor = GL_FALSE;
  189. }
  190.  
  191.  
  192. /*
  193.  * Caller:  context->API.Color4ub pointer.
  194.  */
  195. void gl_Color4ub( GLcontext *ctx,
  196.           GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha )
  197. {
  198.    ASSIGN_4V( ctx->Current.ByteColor, red, green, blue, alpha );
  199.    ASSERT( !ctx->Light.ColorMaterialEnabled );
  200.    ctx->VB->MonoColor = GL_FALSE;
  201. }
  202.  
  203.  
  204. /*
  205.  * Caller:  context->API.Color4ub pointer.
  206.  */
  207. void gl_Color4ubv( GLcontext *ctx, const GLubyte *c )
  208. {
  209.    COPY_4UBV( ctx->Current.ByteColor, c );
  210.    ASSERT( !ctx->Light.ColorMaterialEnabled );
  211.    ctx->VB->MonoColor = GL_FALSE;
  212. }
  213.  
  214.  
  215. /*
  216.  * glColor() which modifies material(s).
  217.  * Caller:  context->API.Color3f pointer.
  218.  */
  219. void gl_ColorMat3f( GLcontext *ctx, GLfloat red, GLfloat green, GLfloat blue )
  220. {
  221.    GLfloat color[4];
  222.    FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Current.ByteColor[0], red);
  223.    FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Current.ByteColor[1], green);
  224.    FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Current.ByteColor[2], blue);
  225.    ctx->Current.ByteColor[3] = 255;
  226.    /* update material */
  227.    ASSERT( ctx->Light.ColorMaterialEnabled );
  228.    ASSIGN_4V( color, red, green, blue, 1.0F );
  229.    gl_set_material( ctx, ctx->Light.ColorMaterialBitmask, color );
  230.    ctx->VB->MonoColor = GL_FALSE;
  231. }
  232.  
  233.  
  234. /*
  235.  * glColor() which modifies material(s).
  236.  * Caller:  context->API.Color3fv pointer.
  237.  */
  238. void gl_ColorMat3fv( GLcontext *ctx, const GLfloat *c )
  239. {
  240.    GLfloat color[4];
  241.    FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Current.ByteColor[0], c[0]);
  242.    FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Current.ByteColor[1], c[1]);
  243.    FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Current.ByteColor[2], c[2]);
  244.    ctx->Current.ByteColor[3] = 255;
  245.    /* update material */
  246.    ASSERT( ctx->Light.ColorMaterialEnabled );
  247.    ASSIGN_4V( color, c[0], c[1], c[2], 1.0F );
  248.    gl_set_material( ctx, ctx->Light.ColorMaterialBitmask, color );
  249.    ctx->VB->MonoColor = GL_FALSE;
  250. }
  251.  
  252.  
  253. /*
  254.  * glColor() which modifies material(s).
  255.  * Caller:  context->API.Color4f pointer.
  256.  */
  257. void gl_ColorMat4f( GLcontext *ctx,
  258.             GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha )
  259. {
  260.    GLfloat color[4];
  261.    FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Current.ByteColor[0], red);
  262.    FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Current.ByteColor[1], green);
  263.    FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Current.ByteColor[2], blue);
  264.    FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Current.ByteColor[3], alpha);
  265.    /* update material */
  266.    ASSERT( ctx->Light.ColorMaterialEnabled );
  267.    ASSIGN_4V( color, red, green, blue, alpha );
  268.    gl_set_material( ctx, ctx->Light.ColorMaterialBitmask, color );
  269.    ctx->VB->MonoColor = GL_FALSE;
  270. }
  271.  
  272.  
  273. /*
  274.  * glColor() which modifies material(s).
  275.  * Caller:  context->API.Color4fv pointer.
  276.  */
  277. void gl_ColorMat4fv( GLcontext *ctx, const GLfloat *c )
  278. {
  279.    GLfloat color[4];
  280.    FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Current.ByteColor[0], c[0]);
  281.    FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Current.ByteColor[1], c[1]);
  282.    FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Current.ByteColor[2], c[2]);
  283.    FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Current.ByteColor[3], c[3]);
  284.    /* update material */
  285.    ASSERT( ctx->Light.ColorMaterialEnabled );
  286.    ASSIGN_4V( color, c[0], c[1], c[2], c[3] );
  287.    gl_set_material( ctx, ctx->Light.ColorMaterialBitmask, color );
  288.    ctx->VB->MonoColor = GL_FALSE;
  289. }
  290.  
  291.  
  292. /*
  293.  * glColor which modifies material(s).
  294.  * Caller:  context->API.Color4ub pointer.
  295.  */
  296. void gl_ColorMat4ub( GLcontext *ctx,
  297.              GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha )
  298. {
  299.    GLfloat color[4];
  300.    ASSIGN_4V( ctx->Current.ByteColor, red, green, blue, alpha );
  301.    /* update material */
  302.    ASSERT( ctx->Light.ColorMaterialEnabled );
  303.    color[0] = red   * (1.0F/255.0F);
  304.    color[1] = green * (1.0F/255.0F);
  305.    color[2] = blue  * (1.0F/255.0F);
  306.    color[3] = alpha * (1.0F/255.0F);
  307.    gl_set_material( ctx, ctx->Light.ColorMaterialBitmask, color );
  308.    ctx->VB->MonoColor = GL_FALSE;
  309. }
  310.  
  311.  
  312. /*
  313.  * glColor which modifies material(s).
  314.  * Caller:  context->API.Color4ub pointer.
  315.  */
  316. void gl_ColorMat4ubv( GLcontext *ctx, const GLubyte *c )
  317. {
  318.    gl_ColorMat4ub( ctx, c[0], c[1], c[2], c[3] );
  319. }
  320.  
  321.  
  322.  
  323. /**********************************************************************/
  324. /******                  glEdgeFlag functions                     *****/
  325. /**********************************************************************/
  326.  
  327. /*
  328.  * Caller:  context->API.EdgeFlag pointer.
  329.  */
  330. void gl_EdgeFlag( GLcontext *ctx, GLboolean flag )
  331. {
  332.    ctx->Current.EdgeFlag = flag;
  333. }
  334.  
  335.  
  336.  
  337. /**********************************************************************/
  338. /*****                    glVertex functions                      *****/
  339. /**********************************************************************/
  340.  
  341. /*
  342.  * Used when in feedback mode.
  343.  * Caller:  context->API.Vertex4f pointer.
  344.  */
  345. static void vertex4f_feedback( GLcontext *ctx,
  346.                    GLfloat x, GLfloat y, GLfloat z, GLfloat w )
  347. {
  348.    struct vertex_buffer *VB = ctx->VB;
  349.    GLuint count = VB->Count;
  350.  
  351.    /* vertex */
  352.    ASSIGN_4V( VB->Obj[count], x, y, z, w );
  353.  
  354.    /* color */
  355.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  356.  
  357.    /* index */
  358.    VB->Findex[count] = ctx->Current.Index;
  359.  
  360.    /* normal */
  361.    COPY_3V( VB->Normal[count], ctx->Current.Normal );
  362.  
  363.    /* texcoord */
  364.    COPY_4V( VB->TexCoord[count], ctx->Current.TexCoord );
  365.  
  366.    /* edgeflag */
  367.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  368.  
  369.    count++;
  370.    VB->Count = count;
  371.    if (count==VB_MAX) {
  372.       gl_transform_vb_part1( ctx, GL_FALSE );
  373.    }
  374. }
  375.  
  376.  
  377. static void vertex3f_feedback( GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z )
  378. {
  379.    vertex4f_feedback(ctx, x, y, z, 1.0F);
  380. }
  381.  
  382.  
  383. static void vertex2f_feedback( GLcontext *ctx, GLfloat x, GLfloat y )
  384. {
  385.    vertex4f_feedback(ctx, x, y, 0.0F, 1.0F);
  386. }
  387.  
  388.  
  389. static void vertex3fv_feedback( GLcontext *ctx, const GLfloat v[3] )
  390. {
  391.    vertex4f_feedback(ctx, v[0], v[1], v[2], 1.0F);
  392. }
  393.  
  394.  
  395.  
  396. /*
  397.  * Only one glVertex4 function since it's not too popular.
  398.  * Caller:  context->API.Vertex4f pointer.
  399.  */
  400. static void vertex4( GLcontext *ctx,
  401.              GLfloat x, GLfloat y, GLfloat z, GLfloat w )
  402. {
  403.    struct vertex_buffer *VB = ctx->VB;
  404.    GLuint count = VB->Count;
  405.  
  406.    ASSIGN_4V( VB->Obj[count], x, y, z, w );
  407.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  408.    COPY_3V( VB->Normal[count], ctx->Current.Normal );
  409.    COPY_4V( VB->TexCoord[count], ctx->Current.TexCoord );
  410.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  411.    VB->VertexSizeMask = VERTEX4_BIT;
  412.  
  413.    count++;
  414.    VB->Count = count;
  415.    if (count==VB_MAX) {
  416.       gl_transform_vb_part1( ctx, GL_FALSE );
  417.    }
  418. }
  419.  
  420.  
  421.  
  422. /*
  423.  * XYZ vertex, RGB color, normal, ST texture coords.
  424.  * Caller:  context->API.Vertex3f pointer.
  425.  */
  426. static void vertex3f_normal_color_tex2( GLcontext *ctx,
  427.                     GLfloat x, GLfloat y, GLfloat z )
  428. {
  429.    struct vertex_buffer *VB = ctx->VB;
  430.    GLuint count = VB->Count;
  431.  
  432.    ASSIGN_3V( VB->Obj[count], x, y, z );
  433.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  434.    COPY_3V( VB->Normal[count], ctx->Current.Normal );
  435.    COPY_2V( VB->TexCoord[count], ctx->Current.TexCoord );
  436.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  437.  
  438.    count++;
  439.    VB->Count = count;
  440.    if (count==VB_MAX) {
  441.       gl_transform_vb_part1( ctx, GL_FALSE );
  442.    }
  443. }
  444.  
  445.  
  446. /*
  447.  * XYZ vertex, RGB color, normal, STRQ texture coords.
  448.  * Caller:  context->API.Vertex3f pointer.
  449.  */
  450. static void vertex3f_normal_color_tex4( GLcontext *ctx,
  451.                     GLfloat x, GLfloat y, GLfloat z )
  452. {
  453.    struct vertex_buffer *VB = ctx->VB;
  454.    GLuint count = VB->Count;
  455.  
  456.    ASSIGN_3V( VB->Obj[count], x, y, z );
  457.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  458.    COPY_3V( VB->Normal[count], ctx->Current.Normal );
  459.    /* GL_SGIS_multitexture */
  460.    COPY_4V( VB->MultiTexCoord[0][count], ctx->Current.MultiTexCoord[0] );
  461.    COPY_4V( VB->MultiTexCoord[1][count], ctx->Current.MultiTexCoord[1] );
  462.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  463.  
  464.    count++;
  465.    VB->Count = count;
  466.    if (count==VB_MAX) {
  467.       gl_transform_vb_part1( ctx, GL_FALSE );
  468.    }
  469. }
  470.  
  471.  
  472. /*
  473.  * XYZ vertex, normal.
  474.  * Caller:  context->API.Vertex3f pointer.
  475.  */
  476. static void vertex3f_normal( GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z )
  477. {
  478.    struct vertex_buffer *VB = ctx->VB;
  479.    GLuint count = VB->Count;
  480.  
  481.    ASSIGN_3V( VB->Obj[count], x, y, z );
  482.    COPY_3V( VB->Normal[count], ctx->Current.Normal );
  483.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  484.  
  485.    count++;
  486.    VB->Count = count;
  487.    if (count==VB_MAX) {
  488.       gl_transform_vb_part1( ctx, GL_FALSE );
  489.    }
  490. }
  491.  
  492.  
  493. /*
  494.  * XYZ vertex, ST texture coords.
  495.  * Caller:  context->API.Vertex3f pointer.
  496.  */
  497. static void vertex3f_color_tex2( GLcontext *ctx,
  498.                  GLfloat x, GLfloat y, GLfloat z )
  499. {
  500.    struct vertex_buffer *VB = ctx->VB;
  501.    GLuint count = VB->Count;
  502.  
  503.    ASSIGN_3V( VB->Obj[count], x, y, z );
  504.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  505.    COPY_2V( VB->TexCoord[count], ctx->Current.TexCoord );
  506.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  507.  
  508.    count++;
  509.    VB->Count = count;
  510.    if (count==VB_MAX) {
  511.       gl_transform_vb_part1( ctx, GL_FALSE );
  512.    }
  513. }
  514.  
  515.  
  516. /*
  517.  * XYZ vertex, STRQ texture coords.
  518.  * Caller:  context->API.Vertex3f pointer.
  519.  */
  520. static void vertex3f_color_tex4( GLcontext *ctx,
  521.                  GLfloat x, GLfloat y, GLfloat z )
  522. {
  523.    struct vertex_buffer *VB = ctx->VB;
  524.    GLuint count = VB->Count;
  525.  
  526.    ASSIGN_3V( VB->Obj[count], x, y, z );
  527.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  528.    COPY_4V( VB->TexCoord[count], ctx->Current.TexCoord );
  529.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  530.  
  531.    count++;
  532.    VB->Count = count;
  533.    if (count==VB_MAX) {
  534.       gl_transform_vb_part1( ctx, GL_FALSE );
  535.    }
  536. }
  537.  
  538.  
  539. /*
  540.  * XYZ vertex, RGB color.
  541.  * Caller:  context->API.Vertex3f pointer.
  542.  */
  543. static void vertex3f_color( GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z )
  544. {
  545.    struct vertex_buffer *VB = ctx->VB;
  546.    GLuint count = VB->Count;
  547.  
  548.    ASSIGN_3V( VB->Obj[count], x, y, z );
  549.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  550.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  551.  
  552.    count++;
  553.    VB->Count = count;
  554.    if (count==VB_MAX) {
  555.       gl_transform_vb_part1( ctx, GL_FALSE );
  556.    }
  557. }
  558.  
  559.  
  560. /*
  561.  * XYZ vertex, color index.
  562.  * Caller:  context->API.Vertex3f pointer.
  563.  */
  564. static void vertex3f_index( GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z )
  565. {
  566.    struct vertex_buffer *VB = ctx->VB;
  567.    GLuint count = VB->Count;
  568.  
  569.    ASSIGN_3V( VB->Obj[count], x, y, z );
  570.    VB->Findex[count] = ctx->Current.Index;
  571.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  572.  
  573.    count++;
  574.    VB->Count = count;
  575.    if (count==VB_MAX) {
  576.       gl_transform_vb_part1( ctx, GL_FALSE );
  577.    }
  578. }
  579.  
  580.  
  581.  
  582. /*
  583.  * XY vertex, RGB color, normal, ST texture coords.
  584.  * Caller:  context->API.Vertex2f pointer.
  585.  */
  586. static void vertex2f_normal_color_tex2( GLcontext *ctx, GLfloat x, GLfloat y )
  587. {
  588.    struct vertex_buffer *VB = ctx->VB;
  589.    GLuint count = VB->Count;
  590.  
  591.    ASSIGN_3V( VB->Obj[count], x, y, 0.0F );
  592.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  593.    COPY_3V( VB->Normal[count], ctx->Current.Normal );
  594.    COPY_2V( VB->TexCoord[count], ctx->Current.TexCoord );
  595.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  596.  
  597.    count++;
  598.    VB->Count = count;
  599.    if (count==VB_MAX) {
  600.       gl_transform_vb_part1( ctx, GL_FALSE );
  601.    }
  602. }
  603.  
  604.  
  605. /*
  606.  * XY vertex, RGB color, normal, STRQ texture coords.
  607.  * Caller:  context->API.Vertex2f pointer.
  608.  */
  609. static void vertex2f_normal_color_tex4( GLcontext *ctx, GLfloat x, GLfloat y )
  610. {
  611.    struct vertex_buffer *VB = ctx->VB;
  612.    GLuint count = VB->Count;
  613.  
  614.    ASSIGN_3V( VB->Obj[count], x, y, 0.0F );
  615.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  616.    COPY_3V( VB->Normal[count], ctx->Current.Normal );
  617.    /* GL_SGIS_multitexture */
  618.    COPY_4V( VB->MultiTexCoord[0][count], ctx->Current.MultiTexCoord[0] );
  619.    COPY_4V( VB->MultiTexCoord[1][count], ctx->Current.MultiTexCoord[1] );
  620.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  621.  
  622.    count++;
  623.    VB->Count = count;
  624.    if (count==VB_MAX) {
  625.       gl_transform_vb_part1( ctx, GL_FALSE );
  626.    }
  627. }
  628.  
  629.  
  630. /*
  631.  * XY vertex, normal.
  632.  * Caller:  context->API.Vertex2f pointer.
  633.  */
  634. static void vertex2f_normal( GLcontext *ctx, GLfloat x, GLfloat y )
  635. {
  636.    struct vertex_buffer *VB = ctx->VB;
  637.    GLuint count = VB->Count;
  638.  
  639.    ASSIGN_3V( VB->Obj[count], x, y, 0.0F );
  640.    COPY_3V( VB->Normal[count], ctx->Current.Normal );
  641.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  642.  
  643.    count++;
  644.    VB->Count = count;
  645.    if (count==VB_MAX) {
  646.       gl_transform_vb_part1( ctx, GL_FALSE );
  647.    }
  648. }
  649.  
  650.  
  651. /*
  652.  * XY vertex, ST texture coords.
  653.  * Caller:  context->API.Vertex2f pointer.
  654.  */
  655. static void vertex2f_color_tex2( GLcontext *ctx, GLfloat x, GLfloat y )
  656. {
  657.    struct vertex_buffer *VB = ctx->VB;
  658.    GLuint count = VB->Count;
  659.  
  660.    ASSIGN_3V( VB->Obj[count], x, y, 0.0F );
  661.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  662.    COPY_2V( VB->TexCoord[count], ctx->Current.TexCoord );
  663.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  664.  
  665.    count++;
  666.    VB->Count = count;
  667.    if (count==VB_MAX) {
  668.       gl_transform_vb_part1( ctx, GL_FALSE );
  669.    }
  670. }
  671.  
  672.  
  673. /*
  674.  * XY vertex, STRQ texture coords.
  675.  * Caller:  context->API.Vertex2f pointer.
  676.  */
  677. static void vertex2f_color_tex4( GLcontext *ctx, GLfloat x, GLfloat y )
  678. {
  679.    struct vertex_buffer *VB = ctx->VB;
  680.    GLuint count = VB->Count;
  681.  
  682.    ASSIGN_3V( VB->Obj[count], x, y, 0.0F );
  683.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  684.    COPY_4V( VB->TexCoord[count], ctx->Current.TexCoord );
  685.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  686.  
  687.    count++;
  688.    VB->Count = count;
  689.    if (count==VB_MAX) {
  690.       gl_transform_vb_part1( ctx, GL_FALSE );
  691.    }
  692. }
  693.  
  694.  
  695. /*
  696.  * XY vertex, RGB color.
  697.  * Caller:  context->API.Vertex2f pointer.
  698.  */
  699. static void vertex2f_color( GLcontext *ctx, GLfloat x, GLfloat y )
  700. {
  701.    struct vertex_buffer *VB = ctx->VB;
  702.    GLuint count = VB->Count;
  703.  
  704.    ASSIGN_3V( VB->Obj[count], x, y, 0.0F );
  705.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  706.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  707.  
  708.    count++;
  709.    VB->Count = count;
  710.    if (count==VB_MAX) {
  711.       gl_transform_vb_part1( ctx, GL_FALSE );
  712.    }
  713. }
  714.  
  715.  
  716. /*
  717.  * XY vertex, color index.
  718.  * Caller:  context->API.Vertex3f pointer.
  719.  */
  720. static void vertex2f_index( GLcontext *ctx, GLfloat x, GLfloat y )
  721. {
  722.    struct vertex_buffer *VB = ctx->VB;
  723.    GLuint count = VB->Count;
  724.  
  725.    ASSIGN_3V( VB->Obj[count], x, y, 0.0F );
  726.    VB->Findex[count] = ctx->Current.Index;
  727.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  728.  
  729.    count++;
  730.    VB->Count = count;
  731.    if (count==VB_MAX) {
  732.       gl_transform_vb_part1( ctx, GL_FALSE );
  733.    }
  734. }
  735.  
  736.  
  737.  
  738.  
  739. /*
  740.  * XYZ vertex, RGB color, normal, ST texture coords.
  741.  * Caller:  context->API.Vertex3f pointer.
  742.  */
  743. static void vertex3fv_normal_color_tex2( GLcontext *ctx, const GLfloat v[3] )
  744. {
  745.    struct vertex_buffer *VB = ctx->VB;
  746.    GLuint count = VB->Count;
  747.  
  748.    COPY_3V( VB->Obj[count], v );
  749.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  750.    COPY_3V( VB->Normal[count], ctx->Current.Normal );
  751.    COPY_2V( VB->TexCoord[count], ctx->Current.TexCoord );
  752.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  753.  
  754.    count++;
  755.    VB->Count = count;
  756.    if (count==VB_MAX) {
  757.       gl_transform_vb_part1( ctx, GL_FALSE );
  758.    }
  759. }
  760.  
  761.  
  762. /*
  763.  * XYZ vertex, RGB color, normal, STRQ texture coords.
  764.  * Caller:  context->API.Vertex3f pointer.
  765.  */
  766. static void vertex3fv_normal_color_tex4( GLcontext *ctx, const GLfloat v[3] )
  767. {
  768.    struct vertex_buffer *VB = ctx->VB;
  769.    GLuint count = VB->Count;
  770.  
  771.    COPY_3V( VB->Obj[count], v );
  772.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  773.    COPY_3V( VB->Normal[count], ctx->Current.Normal );
  774.    /* GL_SGIS_multitexture */
  775.    COPY_4V( VB->MultiTexCoord[0][count], ctx->Current.MultiTexCoord[0] );
  776.    COPY_4V( VB->MultiTexCoord[1][count], ctx->Current.MultiTexCoord[1] );
  777.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  778.  
  779.    count++;
  780.    VB->Count = count;
  781.    if (count==VB_MAX) {
  782.       gl_transform_vb_part1( ctx, GL_FALSE );
  783.    }
  784. }
  785.  
  786.  
  787. /*
  788.  * XYZ vertex, normal.
  789.  * Caller:  context->API.Vertex3f pointer.
  790.  */
  791. static void vertex3fv_normal( GLcontext *ctx, const GLfloat v[3] )
  792. {
  793.    struct vertex_buffer *VB = ctx->VB;
  794.    GLuint count = VB->Count;
  795.  
  796.    COPY_3V( VB->Obj[count], v );
  797.    COPY_3V( VB->Normal[count], ctx->Current.Normal );
  798.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  799.  
  800.    count++;
  801.    VB->Count = count;
  802.    if (count==VB_MAX) {
  803.       gl_transform_vb_part1( ctx, GL_FALSE );
  804.    }
  805. }
  806.  
  807.  
  808. /*
  809.  * XYZ vertex, ST texture coords.
  810.  * Caller:  context->API.Vertex3f pointer.
  811.  */
  812. static void vertex3fv_color_tex2( GLcontext *ctx, const GLfloat v[3] )
  813. {
  814.    struct vertex_buffer *VB = ctx->VB;
  815.    GLuint count = VB->Count;
  816.  
  817.    COPY_3V( VB->Obj[count], v );
  818.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  819.    COPY_2V( VB->TexCoord[count], ctx->Current.TexCoord );
  820.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  821.  
  822.    count++;
  823.    VB->Count = count;
  824.    if (count==VB_MAX) {
  825.       gl_transform_vb_part1( ctx, GL_FALSE );
  826.    }
  827. }
  828.  
  829.  
  830. /*
  831.  * XYZ vertex, STRQ texture coords.
  832.  * Caller:  context->API.Vertex3f pointer.
  833.  */
  834. static void vertex3fv_color_tex4( GLcontext *ctx, const GLfloat v[3] )
  835. {
  836.    struct vertex_buffer *VB = ctx->VB;
  837.    GLuint count = VB->Count;
  838.  
  839.    COPY_3V( VB->Obj[count], v );
  840.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  841.    COPY_4V( VB->TexCoord[count], ctx->Current.TexCoord );
  842.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  843.  
  844.    count++;
  845.    VB->Count = count;
  846.    if (count==VB_MAX) {
  847.       gl_transform_vb_part1( ctx, GL_FALSE );
  848.    }
  849. }
  850.  
  851.  
  852. /*
  853.  * XYZ vertex, RGB color.
  854.  * Caller:  context->API.Vertex3f pointer.
  855.  */
  856. static void vertex3fv_color( GLcontext *ctx, const GLfloat v[3] )
  857. {
  858.    struct vertex_buffer *VB = ctx->VB;
  859.    GLuint count = VB->Count;
  860.  
  861.    COPY_3V( VB->Obj[count], v );
  862.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  863.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  864.  
  865.    count++;
  866.    VB->Count = count;
  867.    if (count==VB_MAX) {
  868.       gl_transform_vb_part1( ctx, GL_FALSE );
  869.    }
  870. }
  871.  
  872.  
  873. /*
  874.  * XYZ vertex, Color index
  875.  * Caller:  context->API.Vertex3f pointer.
  876.  */
  877. static void vertex3fv_index( GLcontext *ctx, const GLfloat v[3] )
  878. {
  879.    struct vertex_buffer *VB = ctx->VB;
  880.    GLuint count = VB->Count;
  881.  
  882.    COPY_3V( VB->Obj[count], v );
  883.    VB->Findex[count] = ctx->Current.Index;
  884.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  885.  
  886.    count++;
  887.    VB->Count = count;
  888.    if (count==VB_MAX) {
  889.       gl_transform_vb_part1( ctx, GL_FALSE );
  890.    }
  891. }
  892.  
  893.  
  894.  
  895. /*
  896.  * Called when outside glBegin/glEnd, raises an error.
  897.  * Caller:  context->API.Vertex4f pointer.
  898.  */
  899. void gl_vertex4f_nop( GLcontext *ctx,
  900.               GLfloat x, GLfloat y, GLfloat z, GLfloat w )
  901. {
  902.    (void) x;
  903.    (void) y;
  904.    (void) z;
  905.    (void) w;
  906.    gl_error( ctx, GL_INVALID_OPERATION, "glVertex4" );
  907. }
  908.  
  909. void gl_vertex3f_nop( GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z )
  910. {
  911.    (void) x;
  912.    (void) y;
  913.    (void) z;
  914.    gl_error( ctx, GL_INVALID_OPERATION, "glVertex3" );
  915. }
  916.  
  917. void gl_vertex2f_nop( GLcontext *ctx, GLfloat x, GLfloat y )
  918. {
  919.    (void) x;
  920.    (void) y;
  921.    gl_error( ctx, GL_INVALID_OPERATION, "glVertex2" );
  922. }
  923.  
  924. void gl_vertex3fv_nop( GLcontext *ctx, const GLfloat v[3] )
  925. {
  926.    (void) v;
  927.    gl_error( ctx, GL_INVALID_OPERATION, "glVertex3v" );
  928. }
  929.  
  930.  
  931.  
  932.  
  933. /**********************************************************************/
  934. /******                   glTexCoord functions                    *****/
  935. /**********************************************************************/
  936.  
  937. /*
  938.  * Caller:  context->API.TexCoord2f pointer.
  939.  */
  940. void gl_TexCoord2f( GLcontext *ctx, GLfloat s, GLfloat t )
  941. {
  942.    ctx->Current.TexCoord[0] = s;
  943.    ctx->Current.TexCoord[1] = t;
  944. }
  945.  
  946.  
  947. /*
  948.  * Caller:  context->API.TexCoord2f pointer.
  949.  * This version of glTexCoord2 is called if glTexCoord[34] was a predecessor.
  950.  */
  951. void gl_TexCoord2f4( GLcontext *ctx, GLfloat s, GLfloat t )
  952. {
  953.    ctx->Current.TexCoord[0] = s;
  954.    ctx->Current.TexCoord[1] = t;
  955.    ctx->Current.TexCoord[2] = 0.0F;
  956.    ctx->Current.TexCoord[3] = 1.0F;
  957. }
  958.  
  959.  
  960. /*
  961.  * Caller:  context->API.TexCoord4f pointer.
  962.  */
  963. void gl_TexCoord4f( GLcontext *ctx, GLfloat s, GLfloat t, GLfloat r, GLfloat q)
  964. {
  965.    ctx->Current.TexCoord[0] = s;
  966.    ctx->Current.TexCoord[1] = t;
  967.    ctx->Current.TexCoord[2] = r;
  968.    ctx->Current.TexCoord[3] = q;
  969.    if (ctx->VB->TexCoordSize==2) {
  970.       /* Have to switch to 4-component texture mode now */
  971.       ctx->VB->TexCoordSize = 4;
  972.       gl_set_vertex_function( ctx );
  973.       ctx->Exec.TexCoord2f = ctx->API.TexCoord2f = gl_TexCoord2f4;
  974.    }
  975. }
  976.  
  977.  
  978. /* GL_SGIS_multitexture / GL_EXT_multitexture */
  979. void gl_MultiTexCoord4f( GLcontext *ctx, GLenum target,
  980.              GLfloat s, GLfloat t, GLfloat r, GLfloat q )
  981. {
  982.    GLint texSet;
  983.    if (target >= GL_TEXTURE0_SGIS && target <= GL_TEXTURE1_SGIS) {
  984.       texSet = target - GL_TEXTURE0_SGIS;
  985.    }
  986.    else if (target >= GL_TEXTURE0_EXT && target <= GL_TEXTURE1_EXT) {
  987.       texSet = target - GL_TEXTURE0_EXT;
  988.    }
  989.    else {
  990.       gl_error(ctx, GL_INVALID_ENUM, "glMultiTexCoord(target)");
  991.       return;
  992.    }
  993.  
  994.    ctx->Current.MultiTexCoord[texSet][0] = s;
  995.    ctx->Current.MultiTexCoord[texSet][1] = t;
  996.    ctx->Current.MultiTexCoord[texSet][2] = r;
  997.    ctx->Current.MultiTexCoord[texSet][3] = q;
  998. }
  999.  
  1000.  
  1001.  
  1002. /*
  1003.  * This function examines the current GL state and sets the
  1004.  * ctx->Exec.Vertex[34]f pointers to point at the appropriate vertex
  1005.  * processing functions.
  1006.  */
  1007. void gl_set_vertex_function( GLcontext *ctx )
  1008. {
  1009.    if (ctx->RenderMode==GL_FEEDBACK) {
  1010.       ctx->Exec.Vertex4f = vertex4f_feedback;
  1011.       ctx->Exec.Vertex3f = vertex3f_feedback;
  1012.       ctx->Exec.Vertex2f = vertex2f_feedback;
  1013.       ctx->Exec.Vertex3fv = vertex3fv_feedback;
  1014.    }
  1015.    else {
  1016.       ctx->Exec.Vertex4f = vertex4;
  1017.       if (ctx->Visual->RGBAflag) {
  1018.      if (ctx->Texture.Enabled >= TEXTURE1_1D) {
  1019.         /* Multi texture coords */
  1020.         ctx->Exec.Vertex2f = vertex2f_normal_color_tex4;
  1021.         ctx->Exec.Vertex3f = vertex3f_normal_color_tex4;
  1022.         ctx->Exec.Vertex3fv = vertex3fv_normal_color_tex4;
  1023.      }
  1024.      else if (ctx->NeedNormals) {
  1025.         /* lighting enabled, need normal vectors */
  1026.         if (ctx->Texture.Enabled) {
  1027.            if (ctx->VB->TexCoordSize==2) {
  1028.           ctx->Exec.Vertex2f = vertex2f_normal_color_tex2;
  1029.           ctx->Exec.Vertex3f = vertex3f_normal_color_tex2;
  1030.           ctx->Exec.Vertex3fv = vertex3fv_normal_color_tex2;
  1031.            }
  1032.            else {
  1033.           ctx->Exec.Vertex2f = vertex2f_normal_color_tex4;
  1034.           ctx->Exec.Vertex3f = vertex3f_normal_color_tex4;
  1035.           ctx->Exec.Vertex3fv = vertex3fv_normal_color_tex4;
  1036.            }
  1037.         }
  1038.         else {
  1039.            ctx->Exec.Vertex2f = vertex2f_normal;
  1040.            ctx->Exec.Vertex3f = vertex3f_normal;
  1041.            ctx->Exec.Vertex3fv = vertex3fv_normal;
  1042.         }
  1043.      }
  1044.      else {
  1045.         /* not lighting, need vertex color */
  1046.         if (ctx->Texture.Enabled) {
  1047.            if (ctx->VB->TexCoordSize==2) {
  1048.           ctx->Exec.Vertex2f = vertex2f_color_tex2;
  1049.           ctx->Exec.Vertex3f = vertex3f_color_tex2;
  1050.           ctx->Exec.Vertex3fv = vertex3fv_color_tex2;
  1051.            }
  1052.            else {
  1053.           ctx->Exec.Vertex2f = vertex2f_color_tex4;
  1054.           ctx->Exec.Vertex3f = vertex3f_color_tex4;
  1055.           ctx->Exec.Vertex3fv = vertex3fv_color_tex4;
  1056.            }
  1057.         }
  1058.         else {
  1059.            ctx->Exec.Vertex2f = vertex2f_color;
  1060.            ctx->Exec.Vertex3f = vertex3f_color;
  1061.            ctx->Exec.Vertex3fv = vertex3fv_color;
  1062.         }
  1063.      }
  1064.       }
  1065.       else {
  1066.      /* color index mode */
  1067.      if (ctx->Light.Enabled) {
  1068.         ctx->Exec.Vertex2f = vertex2f_normal;
  1069.         ctx->Exec.Vertex3f = vertex3f_normal;
  1070.         ctx->Exec.Vertex3fv = vertex3fv_normal;
  1071.      }
  1072.      else {
  1073.         ctx->Exec.Vertex2f = vertex2f_index;
  1074.         ctx->Exec.Vertex3f = vertex3f_index;
  1075.         ctx->Exec.Vertex3fv = vertex3fv_index;
  1076.      }
  1077.       }
  1078.    }
  1079.  
  1080.    if (!ctx->CompileFlag) {
  1081.       ctx->API.Vertex2f = ctx->Exec.Vertex2f;
  1082.       ctx->API.Vertex3f = ctx->Exec.Vertex3f;
  1083.       ctx->API.Vertex4f = ctx->Exec.Vertex4f;
  1084.       ctx->API.Vertex3fv = ctx->Exec.Vertex3fv;
  1085.    }
  1086. }
  1087.  
  1088.  
  1089.  
  1090. /*
  1091.  * This function examines the current GL state and sets the
  1092.  * ctx->Exec.Color[34]* pointers to point at the appropriate vertex
  1093.  * processing functions.
  1094.  */
  1095. void gl_set_color_function( GLcontext *ctx )
  1096. {
  1097.    ASSERT( !INSIDE_BEGIN_END(ctx) );
  1098.  
  1099.    if (ctx->Light.ColorMaterialEnabled) {
  1100.       ctx->Exec.Color3f = gl_ColorMat3f;
  1101.       ctx->Exec.Color3fv = gl_ColorMat3fv;
  1102.       ctx->Exec.Color4f = gl_ColorMat4f;
  1103.       ctx->Exec.Color4fv = gl_ColorMat4fv;
  1104.       ctx->Exec.Color4ub = gl_ColorMat4ub;
  1105.       ctx->Exec.Color4ubv = gl_ColorMat4ubv;
  1106.    }
  1107.    else {
  1108.       ctx->Exec.Color3f = gl_Color3f;
  1109.       ctx->Exec.Color3fv = gl_Color3fv;
  1110.       ctx->Exec.Color4f = gl_Color4f;
  1111.       ctx->Exec.Color4fv = gl_Color4fv;
  1112.       ctx->Exec.Color4ub = gl_Color4ub;
  1113.       ctx->Exec.Color4ubv = gl_Color4ubv;
  1114.    }
  1115.    if (!ctx->CompileFlag) {
  1116.       ctx->API.Color3f = ctx->Exec.Color3f;
  1117.       ctx->API.Color3fv = ctx->Exec.Color3fv;
  1118.       ctx->API.Color4f = ctx->Exec.Color4f;
  1119.       ctx->API.Color4fv = ctx->Exec.Color4fv;
  1120.       ctx->API.Color4ub = ctx->Exec.Color4ub;
  1121.       ctx->API.Color4ubv = ctx->Exec.Color4ubv;
  1122.    }
  1123. }
  1124.  
  1125.  
  1126.  
  1127. /**********************************************************************/
  1128. /*****                    Evaluator vertices                      *****/
  1129. /**********************************************************************/
  1130.  
  1131.  
  1132. /*
  1133.  * Process a vertex produced by an evaluator.
  1134.  * Caller:  eval.c
  1135.  * Input:  vertex - the X,Y,Z,W vertex
  1136.  *         normal - normal vector
  1137.  *         color - 4 integer color components
  1138.  *         index - color index
  1139.  *         texcoord - texture coordinate
  1140.  */
  1141. void gl_eval_vertex( GLcontext *ctx,
  1142.              const GLfloat vertex[4], const GLfloat normal[3],
  1143.              const GLubyte color[4],
  1144.              GLuint index,
  1145.              const GLfloat texcoord[4] )
  1146. {
  1147.    struct vertex_buffer *VB = ctx->VB;
  1148.    GLuint count = VB->Count;  /* copy to local var to encourage optimization */
  1149.    GLuint texSet = ctx->Texture.CurrentTransformSet;
  1150.  
  1151.    VB->VertexSizeMask = VERTEX4_BIT;
  1152.    VB->MonoNormal = GL_FALSE;
  1153.    COPY_4V( VB->Obj[count], vertex );
  1154.    COPY_3V( VB->Normal[count], normal );
  1155.    COPY_4UBV( VB->Fcolor[count], color );
  1156.    
  1157. #ifdef GL_VERSION_1_1
  1158.    if (ctx->Light.ColorMaterialEnabled
  1159.        && (ctx->Eval.Map1Color4 || ctx->Eval.Map2Color4)) {
  1160.       GLfloat fcolor[4];
  1161.       fcolor[0] = color[0] * (1.0F / 255.0F);
  1162.       fcolor[1] = color[1] * (1.0F / 255.0F);
  1163.       fcolor[2] = color[2] * (1.0F / 255.0F);
  1164.       fcolor[3] = color[3] * (1.0F / 255.0F);
  1165.       gl_set_material( ctx, ctx->Light.ColorMaterialBitmask, fcolor );
  1166.    }
  1167. #endif
  1168.    VB->Findex[count] = index;
  1169.    COPY_4V( VB->MultiTexCoord[texSet][count], texcoord );
  1170.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  1171.  
  1172.    count++;
  1173.    VB->Count = count;
  1174.    if (count==VB_MAX) {
  1175.       gl_transform_vb_part1( ctx, GL_FALSE );
  1176.    }
  1177. }
  1178.  
  1179.  
  1180.  
  1181.  
  1182.  
  1183. /**********************************************************************/
  1184. /*****                    glBegin / glEnd                         *****/
  1185. /**********************************************************************/
  1186.  
  1187.  
  1188. #ifdef PROFILE
  1189. static GLdouble begin_time;
  1190. #endif
  1191.  
  1192. #ifdef PROFILE
  1193. #define START_PROFILE t0 = gl_time();
  1194. #define END_PROFILE( TIMER) TIMER += (gl_time() - t0);
  1195.  
  1196.   GLdouble t0;
  1197.   extern GLdouble prof1_time,prof2_time,prof3_time,prof4_time,prof5_time,prof6_time,prof7_time,prof8_time,profrender_time;
  1198. #else
  1199. #define START_PROFILE
  1200. #define END_PROFILE( TIMER)
  1201. #endif
  1202.  
  1203.  
  1204. void gl_Begin( GLcontext *ctx, GLenum p )
  1205. {
  1206.    struct vertex_buffer *VB = ctx->VB;
  1207.    struct pixel_buffer *PB = ctx->PB;
  1208.  
  1209. #ifdef PROFILE
  1210.    begin_time = gl_time();
  1211. #endif
  1212.    if (INSIDE_BEGIN_END(ctx)) {
  1213.       gl_error( ctx, GL_INVALID_OPERATION, "glBegin" );
  1214.       return;
  1215.    }
  1216.    if (ctx->NewModelViewMatrix) {
  1217.       gl_analyze_modelview_matrix(ctx);
  1218.    }
  1219.    if (ctx->NewProjectionMatrix) {
  1220.       gl_analyze_projection_matrix(ctx);
  1221.    }
  1222.    if (ctx->NewState) {
  1223.       gl_update_state(ctx);
  1224.    }
  1225.    else if (ctx->Exec.Vertex3f==gl_vertex3f_nop) {
  1226.       gl_set_vertex_function(ctx);
  1227.    }
  1228.  
  1229.    if (ctx->Driver.Begin) {
  1230.       (*ctx->Driver.Begin)( ctx, p );
  1231.    }
  1232.  
  1233.    ctx->Primitive = p;
  1234.    VB->Start = VB->Count = 0;
  1235.  
  1236.    VB->MonoColor = ctx->MonoPixels;
  1237.    VB->MonoNormal = GL_TRUE;
  1238.    if (VB->MonoColor) {
  1239.       /* All pixels generated are likely to be the same color so have
  1240.        * the device driver set the "monocolor" now.
  1241.        */
  1242.       if (ctx->Visual->RGBAflag) {
  1243.      GLubyte r = ctx->Current.ByteColor[0];
  1244.      GLubyte g = ctx->Current.ByteColor[1];
  1245.      GLubyte b = ctx->Current.ByteColor[2];
  1246.      GLubyte a = ctx->Current.ByteColor[3];
  1247.      (*ctx->Driver.Color)( ctx, r, g, b, a );
  1248.       }
  1249.       else {
  1250.      (*ctx->Driver.Index)( ctx, ctx->Current.Index );
  1251.       }
  1252.    }
  1253.  
  1254.    /* By default use front color/index.  Two-sided lighting may override. */
  1255.    VB->Color = VB->Fcolor;
  1256.    VB->Index = VB->Findex;
  1257.    VB->Specular = VB->Fspec;
  1258.  
  1259.    switch (ctx->Primitive) {
  1260.       case GL_POINTS:
  1261.      ctx->LightTwoSide = GL_FALSE;
  1262.      PB_INIT( PB, GL_POINT );
  1263.      break;
  1264.       case GL_LINES:
  1265.       case GL_LINE_STRIP:
  1266.       case GL_LINE_LOOP:
  1267.      ctx->LightTwoSide = GL_FALSE;
  1268.      ctx->StippleCounter = 0;
  1269.      PB_INIT( PB, GL_LINE );
  1270.      break;
  1271.       case GL_TRIANGLES:
  1272.       case GL_TRIANGLE_STRIP:
  1273.       case GL_TRIANGLE_FAN:
  1274.       case GL_QUADS:
  1275.       case GL_QUAD_STRIP:
  1276.       case GL_POLYGON:
  1277.      ctx->LightTwoSide = ctx->Light.Enabled && ctx->Light.Model.TwoSide;
  1278.      PB_INIT( PB, GL_POLYGON );
  1279.      break;
  1280.       default:
  1281.      gl_error( ctx, GL_INVALID_ENUM, "glBegin" );
  1282.      ctx->Primitive = GL_BITMAP;
  1283.    }
  1284. }
  1285.  
  1286.  
  1287.  
  1288. void gl_End( GLcontext *ctx )
  1289. {
  1290.    struct pixel_buffer *PB = ctx->PB;
  1291.    struct vertex_buffer *VB = ctx->VB;
  1292.  
  1293.    if (ctx->Primitive==GL_BITMAP) {
  1294.       /* glEnd without glBegin */
  1295.       gl_error( ctx, GL_INVALID_OPERATION, "glEnd" );
  1296.       return;
  1297.    }
  1298.    if (VB->Count > VB->Start) {
  1299.       gl_transform_vb_part1( ctx, GL_TRUE );
  1300.    }
  1301.    if (PB->count>0) {
  1302.       gl_flush_pb(ctx);
  1303.    }
  1304.  
  1305.    if (ctx->Driver.End) {
  1306.       (*ctx->Driver.End)(ctx);
  1307.    }
  1308.  
  1309.    PB->primitive = ctx->Primitive = GL_BITMAP;  /* Default mode */
  1310.  
  1311. #ifdef PROFILE
  1312.    ctx->BeginEndTime += gl_time() - begin_time;
  1313.    ctx->BeginEndCount++;
  1314. #endif
  1315. }
  1316.  
  1317.